package sve;

public class CommandParser {

	private static String[] keys;

	public static String parse(String[] args, String key) throws Exception {
		return parse(args, key, -1);
	}

	public static String parse(String[] args, String key, int index) throws Exception {
		String cmd = "";
		int i = Utils.indexOf(args, key);
		if (i > 0) {
			cmd = args[i];
		} else if (i < 0 && index > 0) {
			cmd = args[index];
		} else
			throw new Exception("Incorrect command format. Check the params.");
		return cmd;
	}

	public static String[][] parseAssignments(String a) {
		String[] s = a.split(",");
		String[][] vals = new String[2][s.length];
		int idx = 0;
		for (String ss : s) {
			String[] t = ss.split("=");
			if (s.length == 0 || t.length <= 1)
				continue;
			vals[0][idx] = t[0].trim();
			vals[1][idx] = t[1].trim();
			idx++;
		}

		return vals;
	}

}
